<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../../../Workerman/Autoloader.php';
require_once __DIR__.'/../../../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/../../..');

$page_groupId = GROUP_RESTAURANT_MNG;
$page_pageId = '商铺详情';

require "../framepages/moudle_base.php";

$mode = $_POST['mode'];
$result = 'normal';
if ($mode == 'res_update') {
    $restaurant_id = $_POST['restaurant_id'];
    $restaurant_name = $_POST['restaurant_name'];
    $contact_name = $_POST['contact_name'];
    $contact_number = $_POST['contact_number'];
    $business_licence_img = $_POST['business_licence_img'];
    $catering_licence_img = $_POST['catering_licence_img'];
    $special_permission_img = $_POST['special_permission_img'];
    $personal_credentials_img = $_POST['personal_credentials_img'];
    $permission_status = $_POST['permission_status'];

    $restaurant_record = \Data\Restaurant_DAO::getRecord($restaurant_id);
    $restaurant_record->setRESTAURANT_NAME($restaurant_name);
    $restaurant_record->setCONTACT_NAME($contact_name);
    $restaurant_record->setCONTACT_NUMBER($contact_number);
    \Data\Restaurant_DAO::update($restaurant_record);

    $restaurant_certification_record = \Data\Restaurant_certification_DAO::getRecord($restaurant_id);
    $restaurant_certification_record->setBUSINESS_LICENCE_IMG($business_licence_img);
    $restaurant_certification_record->setCATERING_LICENCE_IMG($catering_licence_img);
    $restaurant_certification_record->setSPECIAL_PERMISSION_IMG($special_permission_img);
    $restaurant_certification_record->setPERSONAL_CREDENTIALS_IMG($personal_credentials_img);
    $restaurant_certification_record->setPERMMISION_STATUS($permission_status);
    \Data\Restaurant_certification_DAO::update($restaurant_certification_record);

    $result = 'succ_update_res';
}
?>
<div class="main-content">
    <div class="row">
        <div>
            <?php

                $restaurant_id = $_GET['restaurant_id'];
                $restaurant_record = \Data\Restaurant_DAO::getRecord($restaurant_id);
                $restaurant_name = $restaurant_record->getRESTAURANT_NAME();
                $contact_name = $restaurant_record->getCONTACT_NAME();
                $contact_number = $restaurant_record->getCONTACT_NUMBER();
                $description = $restaurant_record->getDESCRIPTION();
                $announcement = $restaurant_record->getANNOUNCEMENT();
                $is_opening = $restaurant_record->getIS_OPENING();
                $opening_time = $restaurant_record->getIS_OPENING();
                $province = $restaurant_record->getPROVINCE();
                $city = $restaurant_record->getCITY();
                $county = $restaurant_record->getCOUNTY();
                $detail = $restaurant_record->getDETAIL();
                $created_on = $restaurant_record->getCREATED_ON();

                $restaurant_certification_record = \Data\Restaurant_certification_DAO::getRecord($restaurant_id);
                $business_licence_img = $restaurant_certification_record->getBUSINESS_LICENCE_IMG();
                $catering_licence_img = $restaurant_certification_record->getCATERING_LICENCE_IMG();
                $special_permission_img = $restaurant_certification_record->getSPECIAL_PERMISSION_IMG();
                $personal_credentials_img = $restaurant_certification_record->getPERSONAL_CREDENTIALS_IMG();
                $permission_status = $restaurant_certification_record->getPERMMISION_STATUS();


            ?>

            <div style="background-color: ">
                <br />
                <h4 style="margin-left: 2%;">商铺运营信息</h4>
                <br />
                <table class="res-table"  >
                    <tr>
                        <td width="15%" style="text-align: right">商铺名称：</td>
                        <td width="35%" ><?php echo $restaurant_name ?></td>
                        <td width="15%" style="text-align: right">描述：</td>
                        <td ><?php echo $description ?></td>
                    </tr>


                    <tr>
                        <td  style="height: 160px; text-align: right;vertical-align:top" >公告：</td>
                        <td style="vertical-align: top"><?php echo $announcement ?></td>
                    </tr>

                    <tr>
                        <td style="text-align: right">营业状态：</td>
                        <td>
                            <?php
                            if ($is_opening == STATE_YES){
                                echo "营业中";
                            } elseif($is_opening == STATE_NO) {
                                echo "店铺休息";
                            }
                            ?>
                        </td>
                    </tr>

                    <tr>
                        <td style="text-align: right">日营业时间：</td>
                        <td><?php echo $opening_time ?></td>
                    </tr>

                    <tr>
                        <td style="text-align: right">商铺联系人：</td>
                        <td><?php echo $contact_name ?></td>
                        <td style="text-align: right">联系电话：</td>
                        <td><?php echo $contact_number ?></td>
                    </tr>

                    <tr>
                        <td style="text-align: right">地址：</td>
                        <td><?php echo $province."-".$city."-".$county."-".$detail ?></td>
                    </tr>
                </table>
            </div>
            <br />
            <hr width="100%" size=1 color=#00ffff  noshade>

            <br />
            <br />
            <div id="res-cer-info" class="res-cer-table" style="position: relative;; width:80%;">
                <h4 style="margin-left: 2%">商铺认证信息</h4>
                <br />

                <table class="res-certifi" width="80%">
                    <tr>
                        <td class="certifi-title" style="padding:10px;vertical-align: top; width:13%;">营业执照</td>
                        <td><img src="<?php echo $business_licence_img ?>"></td>

                        <td class="certifi-title" style="padding:10px;vertical-align: top; width:13%;">餐饮许可证</td>
                        <td><img src="<?php echo $catering_licence_img ?>"></td>
                    </tr>

                    <tr>
                        <td class="certifi-title" style="padding:10px;vertical-align: top; width:13%;">特许证件</td>
                        <td><img src="<?php echo $special_permission_img ?>"></td>

                        <td class="certifi-title" style="padding:10px;vertical-align: top; width:13%;">个人证件</td>
                        <td><img src="<?php echo $personal_credentials_img ?>"></td>
                    </tr>

                    <tr>
                        <td style="height:80px">审核状态</td>
                        <td style="height:80px">
                            <?php
                                if ($permission_status == PERMISSION_PROCESS) {
                                    echo "审核中";
                                } elseif ($permission_status == PERMISSION_SUCCESS) {
                                    echo "审核通过";
                                } elseif ($permission_status == PERMISSION_FAIL) {
                                    echo "审核未通过";
                                }

                            ?>
                        </td>
                    </tr>
                </table>
                <div class="btn-toolbar list-toolbar" style="margin-left:28%;">
                    <button type="submit" class="btn btn-danger" onclick="toUpdate(<?php echo $permission_status ?>)">修改认证</button>
                </div>
            </div>


            <div id="res-cer-update" class="main-content" style="margin-left:2%; display:none">
                <h4>修改商铺认证信息</h4>
                <form method="post" action="">
                    <input type="hidden" name="mode" id="mode" value="res_update">
                    <input type="hidden" name="id" id="id" value="<?php echo $restaurant_id ?>">
                    <table style="border-collapse: separate;border-spacing: 0 10px">
                        <tr>
                            <td>商铺名称：</td>
                            <td><input type="text" id="restaurant_name" name="restaurant_name" value="<?php echo $restaurant_name ?>" ><td>
                            <td>联系人：</td>
                            <td><input type="text" id="contact_name" name="contact_name" value="<?php echo $contact_name ?>" ><td>
                        </tr>

                        <tr>
                            <td>手机号：</td>
                            <td><input type="text" id="contact_number" name="contact_number" value="<?php echo $contact_number?>" ><td>
                        </tr>
                        <tr>
                            <td>营业执照：</td>
                            <td><input type="file" id="business_licence_img" name="business_licence_img" value="<?php echo $business_licence_img ?>"><td>
                        </tr>
                        <tr>
                            <td>餐饮许可证：</td>
                            <td><input type="file" id="catering_licence_img" name="catering_licence_img" value="<?php echo $catering_licence_img ?>"><td>
                        </tr>
                        <tr>
                            <td>特许证件：</td>
                            <td><input type="file" id="special_permission_img" name="special_permission_img" value="<?php echo $special_permission_img ?>"><td>
                        </tr>
                        <tr>
                            <td>个人证件：</td>
                            <td><input type="file" id="personal_credentials_img" name="personal_credentials_img" value="<?php echo $personal_credentials_img ?>"><td>
                        </tr>
                        <tr>
                            <td>审核状态：</td>
                            <td><input type="radio" id="permission_status0" name="permission_status" value="<?php echo PERMISSION_PROCESS ?>" >审核中&nbsp;&nbsp;&nbsp;
                                <input type="radio" id="permission_status1" name="permission_status" value="<?php echo PERMISSION_SUCCESS ?>" >审核通过&nbsp;&nbsp;&nbsp;
                                <input type="radio" id="permission_status2" name="permission_status" value="<?php echo PERMISSION_FAIL ?>" >审核未通过
                            <td>
                        </tr>

                    </table>
                    <div class="btn-toolbar list-toolbar">
                        <input type="submit" class="btn btn-danger" value="提交">
                    </div>
                </form>
        </div>
    </div>



    <?php
    require "../framepages/footer.php";
    ?>
</div>
</div>
<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script>
    function init() {
        var msg = '<?php echo $result ?>';
        if (msg == 'succ_update_res') {
            alert('商铺认证信息修改成功');
        }
    }

    function toUpdate(permission_status) {
        document.getElementById("res-cer-info").style.display="none";
        document.getElementById("res-cer-update").style.display="block";
        if (permission_status == 0) {
            document.getElementById('permission_status0').checked = 'checked';
        }
        if (permission_status == 1) {
            document.getElementById('permission_status1').checked = 'checked';
        }
        if (permission_status == 2) {
            document.getElementById('permission_status2').checked = 'checked';
        }
    }
</script>
</body>
</html>
